set hive.exec.dynamic.partition=true;
set hive.exec.dynamic.partition.mode=nonstrict;
set hive.exec.max.dynamic.partitions=250;
set hive.exec.max.dynamic.partitions.pernode=250;

with temp as(
select  a.*, row_number() over(partition by work_order_code order by update_time desc) as rk
from jms_ods.monitor_wo a
WHERE dt BETWEEN DATE_SUB('{{ execution_date | cst_ds }}', 60) AND '{{ execution_date | cst_ds }}')
insert overwrite table jms_dwd.dwd_monitor_wo_dt partition(dt)
select 
id
,work_order_code
,apply_name
,apply_contact_information
,waybill_no
,operation_type_id
,operation_type_name
,problem_piece_id
,problem_piece_code
,problem_type_id
,problem_type_code
,problem_type_name
,problem_type_subject_id
,problem_type_subject_code
,problem_type_subject_name
,problem_description
,apply_cancel_reason
,problem_piece_attachment
,proof_attachment
,video_attachment
,customer_code
,customer_name
,penalty_amount
,award_amount
,subsidy_amount
,handling_fee
,work_order_status
,work_order_source
,apply_review_flag
,responsible_review_flag
,intervention_flag
,appeal_flag
,finish_time
,finish_type
,flow_flag
,subsidy_flow_flag
,create_by
,update_by
,create_by_name
,update_by_name
,status_update_time
,create_time
,update_time
,is_enable
,is_delete
,apply_network_id
,apply_network_code
,apply_network_name
,apply_proxy_id
,apply_proxy_code
,apply_proxy_name
,resp_network_id
,resp_network_code
,resp_network_name
,resp_proxy_id
,resp_proxy_code
,resp_proxy_name
,penalty_network_id
,penalty_network_code
,penalty_network_name
,award_network_id
,award_network_code
,award_network_name
,subsidy_network_id
,subsidy_network_code
,subsidy_network_name
,fee_network_id
,fee_network_code
,fee_network_name
,apply_center_id
,apply_center_code
,apply_center_name
,resp_center_id
,resp_center_code
,resp_center_name
,resp_flag
,package_number_info
,plate_number
,shipment_no
,shipment_name
,resp_attribute
,resp_name
,resp_is_penalty
,resp_penalty_mode
,resp_penalty_amount
,resp_remark
,violation_happen_time
,resp_proxy_penalty_amount
,package_inside_number
,real_package_inside_number
,real_award_amount
,real_penalty_amount
,apply_network_type
,artificial_type
,is_import
,duty_video
,proof_video
,resp_leader
,resp_supervisor
,resp_center_header
,flow_flag_beforehand
,subsidy_flow_flag_beforehand
,substr(create_time,1,10) as dt
from temp
where rk=1
DISTRIBUTE BY 10;
